<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
    <!--[if IE 8]>
    <meta http-equiv="X-UA-Compatible"content="IE=EmulateIE7">
    <link rel="stylesheet" href="${newframe}/css/base/IE8.css" type="text/css"/>
    <![endif]-->
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <script>
        $(document).ready(function() {

            initHosp("hospId");

            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    instrumentType: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    instrumentStatus: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    instrumentNum: {
                        validators: {
                            numeric: true
                        }
                    }
                    <shiro:hasPermission name="super:role">
                    ,
                    hospId: {
                        validators: {
                            notEmpty: true
                        }
                    }
                    </shiro:hasPermission>
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();
                $.ajax({
                    url:'${URL_BASE_UPDATEINSTRUMENT}',
                    type:'post',
                    data:$('#myForm').serialize(),
                    async : false, //默认为true 异步
                    error:function(){
                        alert('error');
                    },
                    success:function(data){
                        closeFrame();
                    }
                });
            });

            //如果是新增，显示数量字段，否则隐藏。
            var method = "${method}";
            if(method == "1"){
                if(typeof($("#div_num").attr("hidden"))=="undefined"){

                }else{
                    $("#div_num").removeAttr("hidden");
                }
            }else{
                $("#div_num").attr("hidden","true");
            }


        });
        //关闭并刷新
        function closeFrame(){
            window.parent.closeModal();
        }

        function formatRepo(repo) {
            if (repo.loading) return repo.text;
            var markup = "<div class='select2-result-repository clearfix'>" +
                "<div class='select2-result-repository__title'>" + repo.hospName + "</div></div>";
            return markup;
        }

        function formatRepoSelection(repo) {
            return repo.hospName;
        }

        function initHosp(id){
            $("#"+id).select2({
                placeholder: '请选医院',
                ajax: {
                    url: '${URL_HL_HOSPITAL_SELECT}',
                    dataType: 'json',
                    type: "post",
                    delay: 250,
                    data: function (params) {
                        var data=new Object();
                        data["iDisplayLength"]=10;
                        if(params.page==undefined){
                            data["iDisplayStart"]=0;
                        }else {
                            data["iDisplayStart"]= (params.page-1)*10;
                        }
                        if(params.term!=undefined){
                            data["hospName"]= params.term;
                        }
                        return data;
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.data,
                            pagination: {
                                more: (params.page * 10) < data.msg
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 0,
                templateResult: formatRepo, // omitted for brevity, see the source of this page
                templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
            });
        }

    </script>
</head>
<body style="width: 98%">
<form id="myForm" class="form-horizontal" method="post" >
    <input type="hidden" id="instrumentId" name="instrumentId" value="${entity.instrumentId}" />
    <div class="clearfix">
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">设备名称</label>
            <div class="col-sm-8">
                <select id="instrumentType" name="instrumentType" class="form-control">
                    <medi:configOpt name="instrumentName" key="${entity.instrumentType}"/>
                </select>
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">设备SN</label>
            <div class="col-sm-8">
                <input type="text" id="instrumentSN" name="instrumentSN" class="form-control" value="${entity.instrumentSN}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">设备型号</label>
            <div class="col-sm-8">
                <input type="text" id="instrmentVersion" name="instrmentVersion" class="form-control" value="${entity.instrmentVersion}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">设备品牌</label>
            <div class="col-sm-8">
                <input type="text" id="instrumentBrand" name="instrumentBrand" class="form-control" value="${entity.instrumentBrand}">
            </div>
        </div>

        <div class="form-group col-sm-6 selectForm">
            <label class="col-sm-4 control-label">设备状态</label>
            <div class="col-sm-8">
                <select id="instrumentStatus" name="instrumentStatus" class="form-control">
                    <medi:configOpt name="instrumentStatus" key="${entity.instrumentStatus}"/>
                </select>
            </div>
        </div>
        <%--所属医院--%>
        <shiro:hasPermission name="super:role">
            <div class="form-group col-sm-6 selectForm">
                <label class="col-sm-4 control-label">所属医院</label>
                <div class="col-sm-8">
                    <select id="hospId" name="hospId"  class="form-control">
                        <c:if test="${hospital!=null}"><option value="${hospital.id}">${hospital.hospName}</option></c:if>
                    </select>
                </div>
            </div>
        </shiro:hasPermission>
        <shiro:lacksPermission name="super:role">
            <input type="hidden" id="hospId" name="hospId" class="form-control" value="${hospital.hospId}">
        </shiro:lacksPermission>

        <%--<div id="div_num" class="form-group col-sm-6">--%>
            <%--<label class="col-sm-4 control-label">数量</label>--%>
            <%--<div class="col-sm-8">--%>
                <%--<input type="text" id="instrumentNum" name="instrumentNum" class="form-control" value="${entity.instrumentNum}">--%>
            <%--</div>--%>
        <%--</div>--%>
    </div>
    <div class="modal-footer" style="text-align: center ">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">关闭</button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>
</body>
</html>